package com.self.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.self.common.constant.CommonConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.self.admin.model.SysRole;
import com.self.admin.mapper.SysRoleMapper;
import com.self.admin.service.SysRoleService;

@Slf4j
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService{

    @Override
    public boolean isSupperAdmin(Long userId) {
        Integer count = baseMapper.existSupperAdmin(userId, CommonConstants.ROLE_ADMIN);
        if (count != null && count > 0){
            return true;
        }
        return false;
    }

    @Override
    public Page<SysRole> findByPage(Page<SysRole> page, String name) {
        return baseMapper.selectPage(page,new LambdaQueryWrapper<SysRole>()
                .like(StringUtils.isNotBlank(name),SysRole::getName,name));
    }
}
